<template>
  <!-- WeChatOfficialAccountLink 微信公众号链接 -->
  <web-view :src="info?.linkUrl" />
</template>

<script lang="ts" setup>
  /**  WeChatOfficialAccountLink  微信公众号链接 */
  import { informationDetails } from '@/api/home';
  import { type InformationPageListResData } from '@/api/home/types';
  import { useAppShare } from '@/hooks/core/useAppShare';
  import { onLoad } from '@/router';
  import { onShareAppMessage } from '@dcloudio/uni-app';
  import { ref } from 'vue';

  const { setWxSharePath } = useAppShare();
  const id = ref();
  const info = ref<InformationPageListResData>();
  onLoad<'RichDetails'>((op) => {
    id.value = op.id;
    getDetails();
  });

  function getDetails() {
    /** 获取资讯详情 */
    id.value &&
      informationDetails(id.value).then((r) => {
        if (r) {
          info.value = r;
          uni.setNavigationBarTitle({
            title: r.title,
          });
        }
      });
  }

  onShareAppMessage(() => {
    return {
      imageUrl: info.value?.coverUrl,
      path: setWxSharePath({ name: 'weChatOfficialAccountLink', options: { id: id.value } }),
      title: info.value?.title,
    };
  });
</script>

<style lang="scss" scoped></style>
